package UseIO.UseTransforStreamRW;

import java.io.*;
import java.nio.charset.Charset;

public class InputStreamRW {
    public static void main(String[] args) throws IOException {
        //inputStream();
        method02();
    }
    // 理解的第一步是很重要的，就是你的理解是什么，决定了后续的很多的事情，
    public static void inputStream() throws IOException {
        // 方式一：11后淘汰了
        InputStreamReader gbk = new InputStreamReader(new FileInputStream("8.内置模块/UseIO/a.txt"));
        OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream("8.内置模块/UseIO/acopy.txt"));

        // 方式二：11之后的操作
        //FileReader gbk = new FileReader("8.内置模块/UseIO/a.txt", Charset.forName("UTF8"));
        FileWriter fw = new FileWriter("8.内置模块/UseIO/a.txt", Charset.forName("UTF8"));
        int b;
        while ((b=gbk.read())!=-1){
            os.write(b);
        }
        gbk.close();
        os.close();
    }

    public static void method02() throws IOException{
        // 通过字节流操作一行的数据
        FileInputStream fileInputStream = new FileInputStream("8.内置模块/UseIO/a.txt");
        InputStreamReader isr = new InputStreamReader(fileInputStream);
        BufferedReader br = new BufferedReader(isr);
        String b;
        while ((b=br.readLine())!=null){
            System.out.println(b);
        }

    }

}
